package com.lwj.liwanjia.utils;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;

import com.lwj.liwanjia.R;
import com.lwj.liwanjia.view.activity.personal.YaoQingActivity;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareAPI;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMWeb;

import retrofit2.http.Url;

/**
 * Created by Administrator on 2017/10/30.
 */

public class ShareDialog extends Dialog implements View.OnClickListener {
    private Context context;
    private TextView tvQQ;
    private TextView tvWx;
    private TextView tvPyq;
    private TextView tvCancle;
    private Activity activity;
    private String url;
    private String title;
    private String des;
    private String iconUrl;

    public ShareDialog(@NonNull Context context, String iconUrl, String url, String title, String des) {
        super(context, R.style.MyDialog);
        setContentView(R.layout.yaoqing_item);
        this.context = context;
        activity = (Activity) context;
        this.url = url;
        this.title = title;
        this.des = des;
        this.iconUrl = iconUrl;
        initView();
        initClick();
    }

    private void initClick() {
        tvPyq.setOnClickListener(this);
        tvQQ.setOnClickListener(this);
        tvWx.setOnClickListener(this);
        tvCancle.setOnClickListener(this);
    }

    private void initView() {
        Window window = getWindow();
        window.setGravity(Gravity.BOTTOM);
        window.setWindowAnimations(R.style.dialog_animation);
        WindowManager.LayoutParams params = window.getAttributes();
        setCanceledOnTouchOutside(false);
        params.width = params.MATCH_PARENT;
        params.height = params.WRAP_CONTENT;
        window.setAttributes(params);
        tvQQ = (TextView) findViewById(R.id.tv_qq);
        tvWx = (TextView) findViewById(R.id.tv_weixin);
        tvPyq = (TextView) findViewById(R.id.tv_penyouquan);
        tvCancle = (TextView) findViewById(R.id.tv_cancle);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_qq:
                ShareUtils.getInstance().startShare(context,0,iconUrl, url, title, des);
                dismiss();
                break;
            case R.id.tv_weixin:
                ShareUtils.getInstance().startShare(context, 1,iconUrl, url, title, des);
                dismiss();
                break;
            case R.id.tv_penyouquan:
                ShareUtils.getInstance().startShare(context, 2, iconUrl,url, title, des);
                dismiss();
                break;
            case R.id.tv_cancle:
                dismiss();
                break;
        }
    }

}
